#ifndef CNODE_H
#define CNODE_H

#include "CRefCounter.h"
#include "typedef.h"

class CNode : public CRefCounter
{

public:
   CNode() : mID(0), mpPredecessor(0) {}
   CNode(const key & key) : mID(key), mpPredecessor(0) {}
   ~CNode()
   {
      if(mpPredecessor != 0)
      {
         mpPredecessor->release();
      }
   }

   inline const key & id() const
   {
      return mID;
   }

   inline CNode * predecessor()
   {
      return mpPredecessor;
   }

   inline void setPredecessor(CNode * predecessor)
   {
      if(mpPredecessor != 0)
      {
         mpPredecessor->release();
      }
      mpPredecessor = predecessor;
      if(mpPredecessor != 0)
      {
         mpPredecessor->addRef();
      }
   }

   inline void setCostFromBeginToHere(const cost & weight)
   {
      mCostFromBeginToHere = weight;
   }

   inline void setCostFromHereToEnd(const cost & weight)
   {
      mCostFromHereToEnd = weight;
   }

   inline const cost & getCostFromBeginToHere() const
   {
      return mCostFromBeginToHere;
   }

   inline const cost & getCostFromHereToEnd() const
   {
      return mCostFromHereToEnd;
   }

   inline void resetCost()
   {
      mCostFromBeginToHere = 0;
      mCostFromHereToEnd = 0;
   }

   inline const cost getCost() const
   {
      return mCostFromBeginToHere + mCostFromHereToEnd; //F
   }

protected:
   key mID;
   CNode * mpPredecessor;

   cost mCostFromBeginToHere; //G
   cost mCostFromHereToEnd;   //H
};

#endif//NODE_H